package com.sec.android.app.myfiles.facade.cmd;

import android.app.ProgressDialog;
import android.content.Context;

import com.sec.android.app.myfiles.R;
import com.sec.android.app.myfiles.log.Log;

import org.puremvc.java.multicore.interfaces.INotification;
import org.puremvc.java.multicore.patterns.command.SimpleCommand;

public class SpinnerProgressCmd extends SimpleCommand {
    public enum OperationProgress {
        SHOW,
        DISMISS,
    }

    private ProgressDialog mProgressDialog = null;
    private Context mContext;

    @Override
    public void execute(INotification notification) {
        Object[] params = (Object[]) notification.getBody();

        mContext = (Context) params[0];
        OperationProgress op = (OperationProgress) params[1];

        switch (op) {
            case SHOW:
                createSpinnerProgress();
                break;
            case DISMISS:
                destroySpinnerProgress();
                break;
            default:
                break;
        }
    }

    private void createSpinnerProgress() {
        destroySpinnerProgress();
        if (mContext != null) {
            mProgressDialog = new ProgressDialog(mContext);
            mProgressDialog.setCancelable(false);
            mProgressDialog.setCanceledOnTouchOutside(false);
            mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
            mProgressDialog.setIndeterminateDrawable(mContext.getDrawable(R.drawable.myfiles_progress_material));
            mProgressDialog.setMessage(this.mContext.getString(R.string.processing));
            mProgressDialog.show();
        } else {
            Log.e(this, "createSpinnerProgress() - Activity is null");
        }
    }

    private void destroySpinnerProgress() {
        if ((mProgressDialog != null) && mProgressDialog.isShowing())
            mProgressDialog.dismiss();
    }

}
